package com.action;

import com.bean.ResponseBean;
import com.pojo.Admin;
import com.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin")
public class AdminAction {

    @Autowired
   private AdminService adminService;

    /**
     * 登录：判断账号密码是否正确
     * @param username  用户名
     * @param password  密码
     * @return  用户对象
     */
    @RequestMapping("/login")
    public ResponseBean login(HttpServletRequest request, String username, String password) {
        Admin admin = adminService.login(username,password);
        request.getSession().setAttribute("admin",admin);
        return new ResponseBean(admin!=null ? 200:500,"用户名或密码错误",null);
    }

}
